package news.dao;

import java.sql.*;

public class BaseDao {

	private static final String DRIVER = "com.mysql.jdbc.Driver";
	private static final String URL = "jdbc:mysql://localhost:3306/news_2";
	private static final String UNAME = "root";
	private static final String UPWD = "root";
	
	private static Connection connection;
	//getConnection()
	public static Connection getConnection(){
		try {
			Class.forName(DRIVER);
			if(connection == null || connection.isClosed()){
				connection = DriverManager.getConnection(URL,UNAME,UPWD);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return connection;
	}
	
	//closeAll()
	public static void closeAll(ResultSet rs,PreparedStatement pstmt,Connection connection){
		try {
			if(rs != null){
				rs.close();
			}
			if(pstmt != null){
				pstmt.close();
			}
			if(connection != null){
				connection.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		
		
	}
	
	
	
	
	
	
}
